import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'
import 'amfe-flexible'
import 'amfe-flexible/index'
// 按需引入vant组件
import { Swipe, SwipeItem, NavBar,Icon,ShareSheet,Overlay,Image as VanImage,Col, Row,Cell, CellGroup, List,PullRefresh ,Divider,Lazyload,Field,Button } from 'vant';
// 导入scrillReveal组件
import scrollReveal from 'scrollreveal'

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css';
import http from './api/home/index';
import { setToken, removeToken, getToken } from './utils/token';

Vue.use(ElementUI);
// 使用vant组件
Vue.use(ShareSheet);
Vue.use(Icon);
Vue.use(NavBar);
Vue.use(Overlay);
Vue.use(VanImage);
Vue.use(Col);
Vue.use(Row);
Vue.use(Cell);
Vue.use(CellGroup);
Vue.use(List);
Vue.use(Divider);
Vue.use(Lazyload);
Vue.use(PullRefresh);
Vue.use(Field);
Vue.use(Button);
Vue.use(Swipe);
Vue.use(SwipeItem);

Vue.config.productionTip = false
Vue.prototype.axios=axios
Vue.prototype.$scrollReveal = scrollReveal();
Vue.prototype.$http = http;
if (process.env.NODE_ENV == 'development') require('./mock/mock');

router.beforeEach((to, from, next) => {
  const token = getToken();
  if (!token && to.path !== '/Login') {
    next('/Login');
  } else if (token && to.path == '/Login') {
    next('/home');
  } else {
    next();
  }
});

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
